Skip to content

[v2.3] Pass RNG to evolution steps#826

Merged
astroJeff merged 11 commits intov2.3from
sg_v2.3_rng_for_steps
Mar 26, 2026
Merged

[v2.3] Pass RNG to evolution steps#826
astroJeff merged 11 commits intov2.3from
sg_v2.3_rng_for_steps

Conversation

@sgossage
Copy link
Copy Markdown
Contributor

@sgossage sgossage commented Mar 18, 2026

This PR is branched from sg_v2.3_fix_ram_usage (PR#818), so contains those changes as well.

Changes in this PR occur in:

  1. posydon/binary_evol/simulationproperties.py
  2. posydon/binary_evol/SN/step_SN.py
  3. posydon/binary_evol/DT/step_detached.py
  4. posydon/binary_evol/MESA/step_mesa.py
  5. posydon/popsyn/binarypopulation.py
  6. posydon/utils/common_functions.py
  7. posydon/unit_tests/utils/test_common_functions.py

In order, the following has been changed:

  1. New RNG keyword arguments for from_ini, load_steps and load_a_step so that a RNG object may be passed to an evolution step.
  2. The StepSN class now looks for/builds an RNG object and uses it to generate randomized SN kicks.
  3. The detached_step class now looks for/builds an RNG object and uses it to calculate Bondi-Hoyle accretion.
  4. The MesaGridStep class now looks for/builds an RNG object and uses it to calculate Bondi-Hoyle accretion.
  5. When creating and evolving a BinaryPopulation, the entropy and resultant RNG object set in your .ini may be passed on to evolution steps. Currently, only step_SN, detached_step, and MesaGridStep pick this up.
  6. The bondi_hoyle() function can be passed an RNG object and it will be used to calculate the Bondi-Hoyle accretion rate.
  7. The unit test for bondi_hoyle() has been updated accordingly.

Now step_SN can have fixed kick outcomes if entropy is set to a specific value in the .ini. Likewise for MesaGridStep and detached_step regarding Bondi-Hoyle accretion. This should allow us to run reproducible binary populations, fixed by the entropy setting.

…operties.py. Adding RNG kwarg to step_SN and using RNG object in places where randomness occurs
@sgossage sgossage requested a review from a team March 18, 2026 20:00
@sgossage sgossage self-assigned this Mar 18, 2026
@sgossage sgossage added the enhancement New feature or request label Mar 18, 2026
@sgossage sgossage changed the title [v2.3] RNG for evolution steps [v2.3] Pass RNG to evolution steps Mar 18, 2026
@sgossage sgossage added this to the v2.3 milestone Mar 19, 2026
@astroJeff
Copy link
Copy Markdown
Contributor

Can we check if this addresses issue #764?

@sgossage
Copy link
Copy Markdown
Contributor Author

sgossage commented Mar 20, 2026

Can we check if this addresses issue #764?

It does @astroJeff , running two separate populations with equal settings produces identical history data frames (ignoring step_times which measures how long each step takes and can differ) with entropy set to a fixed integer. E.g.,

from pandas.testing import assert_frame_equal

# my .ini has kicks enabled, etc, default settings, except entropy = 0
pop1 = BinaryPopulation.from_ini(my_ini_filename, verbose=True)
pop2 = BinaryPopulation.from_ini(my_ini_filename, verbose=True)

pop1.evolve(breakdown_to_df=False, optimize_ram=False, tqdm=True)
pop2.evolve(breakdown_to_df=False, optimize_ram=False, tqdm=True)

hist_df1 = pop1.to_df()
hist_df2 = pop2.to_df()

compare1 = hist_df1.drop(columns=['step_times'])
compare2 = hist_df2.drop(columns=['step_times'])

# this shows no differences exist between the data frames
assert_frame_equal(compare1, compare2)

astroJeff
astroJeff previously approved these changes Mar 26, 2026
@sgossage sgossage dismissed astroJeff’s stale review March 26, 2026 14:39

The merge-base changed after approval.

astroJeff
astroJeff previously approved these changes Mar 26, 2026
@sgossage sgossage dismissed astroJeff’s stale review March 26, 2026 14:45

The merge-base changed after approval.

@elizabethteng elizabethteng self-requested a review March 26, 2026 15:05
@astroJeff astroJeff merged commit 02cd07d into v2.3 Mar 26, 2026
4 checks passed
@astroJeff astroJeff deleted the sg_v2.3_rng_for_steps branch March 26, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants